package cn.xttc.edu.handler;

import cn.xttc.edu.entity.Admin;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 字段填充处理器
 * @author yl
 */
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Autowired
    private HttpSession session;

    @Override
    public void insertFill(MetaObject metaObject) {
        Admin admin = (Admin) session.getAttribute("loginAdmin");
        if (admin != null) {
            this.setFieldValByName( "operatorId", admin.getId(), metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.insertFill(metaObject);
    }
}
